import numpy as np
import pandas as pd
from pandas import DataFrame
import re

def insert_csv(datas):
    df = pd.DataFrame(datas)
    df.to_csv('C:\\Users\\kakaxiiii\\Desktop\\data2.csv',encoding = "utf-8")


df = pd.read_csv('xxy_yang.csv', encoding="gbk")
lines = list()
# read_result:输出是一个索引，然后根据索引查出数据
read_result = df.reset_index().T.to_dict()
for _index in read_result:
    # 获取每行的数据
    lines.append(read_result[_index])
# 多进程加多线线程封装，写入表格
from concurrent.futures import ThreadPoolExecutor, as_completed
from multiprocessing import Process, Manager


# 返回的manager对象控制了一个server进程，此进程包含的python对象可以被其他的进程通过proxies来访问。从而达到多进程间数据通信且安全
def thread_run(_tuple):
    line_list = _tuple
    # 开启进程，利用的是ThreadPoolExecutor，开启100个线程
    executor = ThreadPoolExecutor(max_workers=100)
    all_tasks = [executor.submit(do_data_process, line) for line in line_list]
    data_list = list()
    for future in as_completed(all_tasks):
        result_dict = future.result()
    if result_dict:
        data_list.append(result_dict)

    # d = {}
    # for i in range(len(t0)):
    #     d[t0[i]] = t1_list[i]
    # print(d)
    # c = {"a": t0,
    #      "b": t1}  # 将列表a，b转换成字典
    # data = DataFrame(c)  # 将字典转换成为数据框2022:1:2:3:4:5
    # t0 = ['time_', 'money_', 'class_', 'class_2', 'pay_', 'note']
    # # encoding=utf-8
    # list1 = ["a", "b", "c"]
    # list2 = [1, 2, 3]
    # d = {}
    # for i in range(len(list1)):
    #     d[list1[i]] = list2[i]
    # print(d)
    # df_data1 = pd.DataFrame(d)# 将 一维列表 list 转换为 DataFrame
    # df_data1 = pd.DataFrame(t1_list )  # 将 一维列表 list 转换为 DataFrame
    # 这边可以插入数据

    df = pd.DataFRame（data_list）

    df.to_csv("xx.csv")


def do_data_process():
    # 该功能是数据处理好后返回数据

    pass


# 创建进程6个进程
if __name__ == '__main__':

data_list = []

pool = list()

with Manager() as mess:
    # 创建进程6个进程

    for start_num in range(6):
        p = Process(target=tread_run, args=((data_list[start_num::6]),))

        p.start()

        pool.append(p)

    for p in pool:
        p.join()


————————————————
版权声明：本文为CSDN博主「xxy_yang」的原创文章，遵循CC
4.0
BY - SA版权协议，转载请附上原文出处链接及本声明。
原文链接：https: // blog.csdn.net / xxy_yang / article / details / 81221056